using UnityEngine;
using UnityEngine.UI;

public class CommonUI : MonoBehaviour
{
    private Button _addBtn;
    private Button _reduceBtn;
    private Button _nativeCheckBtn;
    private Text _commonText;
    private Player _player;
    private int _addValue = 2;
    private int _reduceValue = 3;
    private void Awake()
    {
        _player = new Player();
        _addBtn = transform.Find("AddBtn").GetComponent<Button>();
        _reduceBtn = transform.Find("ReduceBtn").GetComponent<Button>();
        _nativeCheckBtn = transform.Find("NativeCheckBtn").GetComponent<Button>();
        _commonText = transform.Find("CommonText").GetComponent<Text>();
        _addBtn.onClick.AddListener(OnAddButtonClick);
        _reduceBtn.onClick.AddListener(OnReduceButtonClick);
        _nativeCheckBtn.onClick.AddListener(OnNativeCheckButtonClick);
    }
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        _commonText.text = $"HP {_player.Hp}  \ndeath {_player.Dead}";
    }

    private void OnAddButtonClick()
    {
        _player.AddHp(_addValue);
        _addBtn.gameObject.SetActive(false);
    }

    private void OnReduceButtonClick()
    {
        _player.ReduceHp(_reduceValue);
    }

    private void OnNativeCheckButtonClick()
    {
        NativeCtrl.Instance.ShowAD((a) =>
        {
            if (a)
            {
                _addBtn.gameObject.SetActive(true);
            }
        });
    }


}
